﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LightWeb.TransferModel;
using LightWeb.Respository;
using LightWeb.DomainModel;
using FlyearAssist.Hibernating.DataModel;

namespace LightWeb.Blog
{
    public partial class ViewArtical : System.Web.UI.Page
    {
        public int ArticalId { get { return int.Parse(this.Request.QueryString["ArticalId"]); } }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadArticalList();
            }
        }

        private void LoadArticalList()
        {
            List<TmArticalComment> summary = new List<TmArticalComment>();

            using (OurTransactionScope ts = new OurTransactionScope())
            {
                var context = DataContext.Current;
                var list = context.Read<ArticalComment>(
                    new List<NCondition> { new NCondition { PropertyName = "ArticalId", Operate = Operation.EQ, PropertyValue = ArticalId } },
                    new List<NOrder> { new NOrder { PropertyName = "Date", OrderType = OrderDirection.ASC } });
                foreach (ArticalComment item in list)
                {
                    summary.Add(ModelConvert.FromDomainModel(item));
                }
            }
            this.repComment.DataSource = summary;
            this.repComment.DataBind();

        }
    }
}